/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.ux.select;

import org.rails.extjs.Option;
import org.rails.extjs.data.Store;
import org.rails.extjs.form.Field;
import org.rails.extjs.toolbar.Toolbar;

public class MultiSelect extends Field {

	public MultiSelect() {
		super();
	}

	public MultiSelect(Option configOptions) {
		super(configOptions);
	}

	public MultiSelect(String name) {
		super(name);
	}

	public MultiSelect(String name, String fieldLabel) {
		super(name, fieldLabel);
	}

	public MultiSelect(String name, String fieldLabel, Object value) {
		super(name, fieldLabel, value);
	}
	
	public void setDDReorder(Boolean ddRecorder){
		addOption("ddReorder",ddRecorder);
	}
	
	public Boolean isDDReorder(){
		return getBoolean("ddReorder",false);
	}
	
	public void setAppendOnly(Boolean appendOnly){
		addOption("appendOnly",appendOnly);
	}
	
	public Boolean isAppendOnly(){
		return getBoolean("appendOnly",false);
	}
	
	public void setDisplayField(int displayField){
		addOption("displayField",displayField);
	}
	
	public void setDisplayField(String displayField){
		addOption("displayField",displayField);
	}
	
	public Object getDisplayField(){
		return getOption("displayField");
	}
	
	public void setValueField(Number valueField){
		addOption("valueField",valueField);
	}
	
	public void setValueField(String valueField){
		addOption("valueField",valueField);
	}
	
	public Object getValueField(){
		return getOption("valueField");
	}
	
	public void setAllowBlank(Boolean allowBlank){
		addOption("allowBlank",allowBlank);
	}
	
	public Boolean isAllowBlank(){
		return getBoolean("allowBlank",true);
	}
	
	public void setMinSelections(Integer minSelections){
		addOption("minSelections",minSelections);
	}
	
	public Integer getMinSelections(){
		return getInteger("minSelections",0);
	}
	
	public void setMaxSelections(Integer maxSelections){
		addOption("maxSelections",maxSelections);
	}
	
	public Integer getMaxSelections(){
		return getInteger("maxSelections",Integer.MAX_VALUE);
	}
	
	public void setBlankText(String blankText){
		addOption("blankText", blankText);
	}
	
	public String getBlankText(){
		return getString("blankText","This field is required");
	}
	
	public void setMinSelectionsText(String minSelectionsText){
		addOption("minSelectionsText",minSelectionsText);
	}
	
	public String getMinSelectionsText(){
		return getString("minSelectionsText","Minimum {0} item(s) required");
	}
	
	public void setMaxSelectionsText(String maxSelectionsText){
		addOption("maxSelectionsText",maxSelectionsText);
	}
	
	public String getMaxSelectionsText(){
		return getString("maxSelectionsText","Maximum {0} item(s) allowed");
	}
	
	public void setDelimiter(String delimiter){
		addOption("delimiter", delimiter);
	}
	
	public String getDelimiter(){
		return getString("delimiter",",");
	}
	
	public void setStore(Store store){
		addOption("store",store);
	}
	
	public Store getStore(){
		return (Store)getOption("store");
	}
	
	public void setTbar(Toolbar tbar){
		addOption("tbar",tbar);
	}
	
	public Toolbar getTbar(){
		return (Toolbar)getOption("tbar");
	}

	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		addOption("xtype","multiselect");
		script.append(createOptions());
		return script.toString();
	}
	
}
